{extend name='common/container'}
{block name="content"}

<div style="margin:0 15px 15px 15px;">
    <el-card shadow="never" style="min-height:650px;">
        <div v-if="search_visible" id="search" class="search">
            <el-form ref="form" size="small" :model="searchData" inline>

                <el-form-item label="所属币种">
                    <el-select   style="width:100%" v-model="searchData.type" filterable clearable placeholder="请选择所属币种">
                        <el-option v-for="(item,i) in type_list" :key="i" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="币种状态">
                    <el-select   style="width:100%" v-model="searchData.status" filterable clearable placeholder="请选择币种状态">
                        <el-option v-for="(item,i) in status_list" :key="i" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="使用对象">
                    <el-select   style="width:100%" v-model="searchData.business" filterable clearable placeholder="请选择币种使用对象">
                        <el-option v-for="(item,i) in business_list" :key="i" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <search-tool :search_data.sync="searchData" :is_clear.sync="is_clear" @refesh_list="index"></search-tool>
            </el-form>
        </div>
        <div class="btn-group" style="margin-top:10px;margin-bottom:10px;">
            <div>
                <el-button v-for="item in button_group" :key="item.access" v-if="checkPermission(item.access,'{:implode(',',session('admin.access'))}','{:session('admin.role_id')}',[1])" :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname)">
                    <span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
                    <span v-else v-text="item.name"></span>
                </el-button>
                <!--                <el-link style="color: #fff" class="el-button el-button&#45;&#45;success el-button&#45;&#45;mini" href="/Member/diagram" aria-expanded="false">矩阵图</el-link>-->
                <el-link style="color: #fff" class="el-button el-button--success el-button--mini" href="/Member/recommend" aria-expanded="false">推荐图</el-link>
            </div>
            <div><table-tool :search_visible.sync="search_visible"  @refesh_list="index"></table-tool></div>
        </div>
        <el-table  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" v-loading="loading"  ref="multipleTable" border class="eltable" :data="list" :summary-method="getSummaries" show-summary style="width: 100%">
            <el-table-column align="center" type="selection" width="42"></el-table-column>
            <el-table-column align="center" type = '' property="id"  label="编号"  width="70">
            </el-table-column>
            <el-table-column align="center"  property="name" label="自定义名称" width="100">
            </el-table-column>
            <el-table-column align="center"  property="currency_name"  label="币种名称" >
            </el-table-column>
            <el-table-column align="center"  property="price_currency" label="价格对比货币">
            </el-table-column>
            <el-table-column align="center"  property="type" :formatter="type_con" label="币种类型">
            </el-table-column>
            <el-table-column align="center"  property="today_price" label="今日凌晨价格" >
            </el-table-column>
            <el-table-column align="center"  property="current_price" label="当前价格" >
            </el-table-column>
            <el-table-column align="center"  property="acton" label="功能" >
            </el-table-column>
            <el-table-column align="center"  property="status" :formatter="status_con" label="币种状态">
            </el-table-column>
            <el-table-column align="center"  property="business" :formatter="business_con" label="使用对象" >
            </el-table-column>
            <el-table-column :fixed="ismobile()?false:'right'" label="操作" align="center" width="180">
                <template slot-scope="scope">
                    <div v-if="scope.row.id && scope.row.id != 1">
                        <el-button v-if="checkPermission('/admin/currency/edit.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-edit" type="primary" @click="update(scope.row)" >修改</el-button>
                        <el-button v-if="checkPermission('/admin/currency/delete.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-delete" type="danger" @click="del(scope.row)" >删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
    </el-card>

    <!--添加-->
    <Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
    <!--修改-->
    <Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>

</div>

{/block}
{block name="script"}
<script src="__PUBLIC__/assets/js/app.js"></script>
<script src="__PUBLIC__/assets/libs/xlsx/xlsx.core.min.js"></script>
<script src="__PUBLIC__/components/admin/currency/add.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/currency/update.js?v=<?php echo rand(1000,9999)?>"></script>
<script>
    new Vue({
        el: '#app',
        components:{
        },
        data: function() {
            return {
                dialog: {
                    addDialogStatus : false,
                    updateDialogStatus : false,
                },
                searchData:{
                    type:'',
                    status:'',
                    business:''
                },
                button_group:[
                    {name:'添加',color:'success',access:'/admin/Currency/add.html',icon:'el-icon-plus',disabled:'',clickname:'add'},
                ],
                loading: false,
                page_data: {
                    limit: 20,
                    page: 1,
                    total:20,
                },
                order:'',
                sort:'',
                ids: [],
                multiple:true,
                search_visible:true,
                list: [],
                updateInfo:{},
                sum_amount:'',
                is_clear:false,
                status_list:[{'id':1,'name':'开启'},{'id':2,'name':'关闭'}],
                business_list:[{'id':1,'name':'用户直接使用'},{'id':2,'name':'非用户直接使用'}],
                type_list:[{'id':1,'name':'BEP20(币安)'},{'id':2,'name':'TRC20(波场)'},{'id':99,'name':'自定义(未上链)'}],
            }
        },
        methods:{
            index(){
                let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
                Object.assign(param, this.searchData,this.urlobj)
                this.loading = true
                axios.post(base_url + '/Currency/index',param).then(res => {
                    if(res.data.status == 200){
                        this.list = res.data.data.data
                        this.page_data.total = res.data.data.total
                        this.sum_amount = res.data.sum_amount
                        this.loading = false
                    }else{
                        this.$message.error(res.data.msg);
                    }
                })
            },
            add(){
                this.dialog.addDialogStatus = true
            },
            update(row){
                let id = row.id ? row.id : this.ids.join(',')
                axios.post(base_url + '/Currency/getEdit',{id:id}).then(res => {
                    if(res.data.status == 200){
                        this.dialog.updateDialogStatus = true
                        this.updateInfo = res.data.data
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            del(row){
                this.$confirm('确定操作吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let ids = row.id ? row.id : this.ids.join(',')
                    axios.post(base_url + '/Currency/delete',{id:ids}).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.index()
                        }else{
                            this.$message.error(res.data.msg)
                        }
                    })
                }).catch(() => {})
            },
            type_con(row, column, cellValue){
                if (cellValue === 1){
                    return '币安(BEP20)';
                }else if (cellValue === 2){
                    return '波场(TRC20)';
                }else if (cellValue === 99){
                    return '自定义';
                }
            },
            status_con(row, column, cellValue){
                if (cellValue === 1){
                    return '开启';
                }else if (cellValue === 2){
                    return '关闭';
                }
            },
            business_con(row, column, cellValue){
                if (cellValue === 1){
                    return '用户直接使用';
                }else if (cellValue === 2){
                    return '非用户直接使用';
                }
            },

            getSummaries(param) {
                const { columns, data } = param;
                const sums = [];
                columns.forEach((column, index) => {
                    if(index === 1) {
                        sums[index] = '合计'
                    }
                    if(column.label === '积分') {
                        sums[index] = this.sum_amount
                    }
                })
                return sums
            },
            fn(method){
                this[method](this.ids)
            },
        },
        mounted(){
            this.index()
        },
    })
</script>
{/block}
